﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LED_Editor.Model;


namespace LED_Editor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            _frame = Frame.CreateInstance();
            _frame.PropertyChanged += new PropertyChangedEventHandler(_frame_PropertyChanged);
        }

        void _frame_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            MessageBox.Show("Changed");  
        }
        Frame _frame;

        private void button1_Click(object sender, EventArgs e)
        {
            _frame.StartColor = Color.Red;
        }

        Random random = new Random();
        private Control GetControl()
        {
            

            Panel panel = new Panel();
            //panel.Dock = DockStyle.Left ;

            byte red = (byte)random.Next(0, 255);
            byte green = (byte)random.Next(0, 255);
            byte blue = (byte)random.Next(0, 255);
            panel.BackColor = Color.FromArgb(red, green, blue);

            return panel;
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            // this.dataGridView1.data  
            for (int i = 0; i < 5; i++)
            {
                this.flowLayoutPanel1.Controls.Add(GetControl());
            }

            for (int i = 0; i < 10; i++)
            {
                this.flowLayoutPanelEx1.Controls.Add(GetControl());
            }

            hScrollBar1.LargeChange = flowLayoutPanel1.HorizontalScroll.LargeChange;
            hScrollBar1.Maximum = 10000;//flowLayoutPanel1.HorizontalScroll.Maximum;
            hScrollBar1.Minimum = 0;//flowLayoutPanel1.HorizontalScroll.Minimum;
            hScrollBar1.SmallChange = flowLayoutPanel1.HorizontalScroll.SmallChange;
            hScrollBar1.Value = flowLayoutPanel1.HorizontalScroll.Value;


            //flowLayoutPanelEx1.HorizontalScroll.Visible = true; 
 

            /////////////////////////////

            Track track1 = Track.CreateInstance() ;
            track1.Name = "Контроллер1";
            track1.Id = 1;

            Track track2 = Track.CreateInstance();
            track2.Name = "Контроллер2";
            track2.Id = 2;

            //dsFrames1.Frames.AddFramesRow(Color.PeachPuff, Color.LightYellow, 100);
            //dsFrames1.Frames.AddFramesRow(Color.SpringGreen , Color.LightYellow, 150);


        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            switch (e.Type )
            {
               case ScrollEventType.EndScroll:
                //case ScrollEventType.ThumbPosition:

                    //flowLayoutPanel1.HorizontalScroll.Value = e.NewValue;
                    //flowLayoutPanelEx1.HorizontalScroll.Value = e.NewValue;
                    break;
                case ScrollEventType.First:
                    break;
                case ScrollEventType.LargeDecrement:
                    break;
                case ScrollEventType.LargeIncrement:
                    break;
                case ScrollEventType.Last:
                    break;
                case ScrollEventType.SmallDecrement:
                    break;
                case ScrollEventType.SmallIncrement:
                    break;
                case ScrollEventType.ThumbTrack:
                    break;
                default:
                    break;
            }
            //flowLayoutPanel1.Scroll(e);
            //e.
           // flowLayoutPanel1.HorizontalScroll.Value = e.NewValue;
            //flowLayoutPanel1.i 
            //flowLayoutPanel1.Hide();
            //flowLayoutPanel1.SuspendLayout(); 


            //flowLayoutPanel1.HorizontalScroll.Value = e.NewValue;
            //flowLayoutPanelEx1.HorizontalScroll.Value = e.NewValue;

           // flowLayoutPanel1.Show();
            //flowLayoutPanel1.ResumeLayout(); 



        }

        private void hScrollBar1_ValueChanged(object sender, EventArgs e)
        {
            //flowLayoutPanel1.HorizontalScroll.Value = hScrollBar1.Value  ;
            //flowLayoutPanelEx1.HorizontalScroll.Value = hScrollBar1.Value;


        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
           // flowLayoutPanel1.AutoScroll = checkBox1.Checked;
        }

        private void bindingSource2_ListChanged(object sender, ListChangedEventArgs e)
        {
            //MessageBox.Show(e.ListChangedType.ToString() );
            object o = bindingSource2.List[0];
        }

        private void bindingSource1_CurrentItemChanged(object sender, EventArgs e)
        {
            listView1.Items.Add("CurrentItemChanged!");  
        }

        private void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
        {
            listView1.Items.Add(e.ListChangedType.ToString());  
        }

        private void kryptonNumericUpDown1_ValueChanged(object sender, EventArgs e)
        {
          //  timeLinePanel1.ScaleFactor = (int)kryptonNumericUpDown1.Value; 
        }

        private void kryptonSlider1_ValueChanged(AC.ExtendedRenderer.Toolkit.KryptonSlider Sender, AC.ExtendedRenderer.Toolkit.KryptonSlider.SliderEventArgs e)
        {
            int percents = 0;
            if (e.NewValue <= 0)
            {
                percents = (e.NewValue + kryptonSlider1.Range / 2) * kryptonSlider1.Range / 200;
            }
            else
            {
                percents = e.NewValue * 20 + 100;

            }
            // tracksControl1.PerformScale(percents);

           // trackEditorControl1.PerformScale(percents);
            kryptonLabel1.Text = percents + " %" + "("+e.NewValue+")";
            timeLinePanel1.ScaleFactor = percents; 

        }


    }

    public class FlowLayoutPanelEx : FlowLayoutPanel
    {
        public FlowLayoutPanelEx()
        {
            this.Scroll += new ScrollEventHandler(FlowLayoutPanelEx_Scroll); 
        }

        void FlowLayoutPanelEx_Scroll(object sender, ScrollEventArgs e)
        {
            int i = e.NewValue;
            //throw new NotImplementedException();
        }

        //public void Scroll(ScrollEventArgs args)
        //{
        //    OnScroll(args);
        //}
    }
}


